<?php defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * @author  Tran Van Thanh
 * @email   thanhtran@vietnambiz.com
 * @date    07.09.2011
 */
 
class Booking_model extends MY_Model {
    
    function __construct()
    {
        parent::__construct();
        $this->_table = 'booking';
    }
    
    function get_all_booking($page = 1)
    {
    	$limit = $this->config->item('booking', 'limit');
    	return $this->limit($limit, ($page - 1)*$limit)->get_all();
    }
    
    function get_booking_info($booking_id = null)
    {
    	$this->db->select('a.*')
                 ->from('booking as a')               
                 ->where('id',$booking_id);
        $q = $this->db->get();
       
        return $q->row();
    }
    
    function get_customer_info_by_id($id_customer = null)
    {   	
    	$this->db->select()
                 ->from('customers')
                 ->where('id',$id_customer);
        $q = $this->db->get();
       
        return $q->row();
    }
    
    function get_products_info_by_id($id_products = null)
    {
    	$this->db->select()
                 ->from('products')
                 ->where('id',$id_products);
        $q = $this->db->get();
       
        return $q->row();
    }
    
	function get_images_products_by_product_id($product_id = null)
	{
		$this->db->select()
                 ->from("images_products")
                 ->where('id_product',$product_id)
                 ->order_by('date_create DESC'); 
        $q = $this->db->get();
        $result = $q->result();
        $q->free_result();        
        return $result; 
	}
    
	function delete_booking($booking_id)
    {
        if(is_numeric($booking_id)) {
        	$a[] = $booking_id;
        	$booking_id = $a;
        }    	
    	$this->db->where_in('id', $booking_id)->delete('booking');
    	$this->delete_many($booking_id);
    }
}